<?php
include 'util/BeanJSONEncoder.php';
include 'util/BeanJSONDecoder.php';

class ConversationController extends Zend_Controller_Action
{

	public function init()
	{
		/* Initialize action controller here */
	}

	public function indexAction()
	{
		// dispatch
		
		if ($this->getRequest()->isPost()) {
			$request_body = @file_get_contents('php://input');
			$this->doPost($request_body);
		} else {
			$this->doGet();
		}
		exit;
	}

	protected function doPost($request_body) {
		$ps = new Application_Model_PersistenceService();
		
		$conversation = Application_util_BeanJSONDecoder::decode($request_body, Zend_Json::TYPE_OBJECT);
		$conversation->setTimestamp(date('Y-m-d H:i:s'));
		
		$ps->saveConversation($conversation);
		
		$json = Application_util_BeanJSONEncoder::encode($conversation);
		$this->getResponse()->setHeader('Content-Type', 'application/json')
                            ->setBody($json)->sendResponse();
		
	}
	
	protected function doGet() {
		// implement me
		echo "doGet NYI";
	}

}

